package com.ax.service.imple;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;

import com.ax.pojo.TabConfig;
import com.ax.service.TabConfigService;
import com.ax.utils.BaseDaoSupport;

@Service("tabConfigService")
public class TabConfigServiceImple implements TabConfigService {

	private BaseDaoSupport<TabConfig> dao;
	
	@Resource(name="sessionFactory")
	public void setSessionFactort(SessionFactory sessionFactory){
		 dao=new BaseDaoSupport<TabConfig>();
		 dao.setSessionFactory(sessionFactory);
	}
	public Map<String, TabConfig> findConfig() {
		List<TabConfig> list=dao.findAll(TabConfig.class);
		Map<String,TabConfig> map=new HashMap<String, TabConfig>();
		for (TabConfig tabConfig : list) {
			map.put(tabConfig.getCtitle(),tabConfig);
		}
		return map;
	}
	public void updateConfig(Map<String, String> map) {
		  Set<String> set=map.keySet();
		  for (String string : set) {
			  String hql="update TabConfig c set c.cvalue=? where c.ctitle=?";
			  dao.executeHQLUpdate(hql, new Object[]{map.get(string),string});
		}
	}

}
